package com.k2data.k2app.util.cas;

import com.nimbusds.jose.EncryptionMethod;
import com.nimbusds.jose.JWEAlgorithm;
import com.nimbusds.jose.JWSAlgorithm;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.jwt.config.encryption.SecretEncryptionConfiguration;
import org.pac4j.jwt.config.signature.SecretSignatureConfiguration;
import org.pac4j.jwt.profile.JwtGenerator;

public class TokenGenerator {
    private static final String SIGNING_SECRET = "RxiKW3a1GEUOgoZHu6monjDlrd8T6R4Gj2KcMNnNbE9d3WkTQLZGy6VG3rCAXk3zg7e2Pp63wMdCHy5haFaZmhEWAVP5Vhsb7O0wC1cNvP9qyEDORO2FegGja7czhBsG44xjJ3RXRvyfNf0APWrZTgoVoY4OeMvlvN781eK58QoZsb0APajUgP831DyQohgX66D95QKU3cbsOhoVVlwCt1d8HuWuO0N6rG6a7tPuPzj5F5PVyHkcLlM5fj9TJozt";
    private static final String ENCRYPTION_SECRET = "FBNMZbGSZc6QfALEVcCcUmweseCGqiNkgzJ1TkSG59FOoR5m";

//    public static void main(String[] args) {
//        String username = "k2data";
//        String token = generateToken(username);
//        System.out.println("username: " + username);
//        System.out.println("token: " + token);
//
//    }

    public static String generateToken(String username) {
        JwtGenerator<CommonProfile> jwtGenerator = new JwtGenerator<>();

        jwtGenerator.setSignatureConfiguration(new SecretSignatureConfiguration(SIGNING_SECRET, JWSAlgorithm.HS256));
        jwtGenerator.setEncryptionConfiguration(new SecretEncryptionConfiguration(ENCRYPTION_SECRET, JWEAlgorithm.DIR, EncryptionMethod.A192CBC_HS384));

        final CommonProfile commonProfile = new CommonProfile();
        commonProfile.setId(username);
        return jwtGenerator.generate(commonProfile);
    }
}
